//
//  BVBusinessModelData.m
//
//  Created by 子  on 16/8/22
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "BVBusinessModelData.h"


NSString *const kBVBusinessModelDataIsDel = @"is_del";
NSString *const kBVBusinessModelDataDistId = @"dist_id";
NSString *const kBVBusinessModelDataCityId = @"city_id";
NSString *const kBVBusinessModelDataId = @"id";
NSString *const kBVBusinessModelDataProvinceId = @"province_id";
NSString *const kBVBusinessModelDataTitle = @"title";
NSString *const kBVBusinessModelDataIntro = @"intro";
NSString *const kBVBusinessModelDataAddTime = @"add_time";


@interface BVBusinessModelData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation BVBusinessModelData

@synthesize isDel = _isDel;
@synthesize distId = _distId;
@synthesize cityId = _cityId;
@synthesize dataIdentifier = _dataIdentifier;
@synthesize provinceId = _provinceId;
@synthesize title = _title;
@synthesize intro = _intro;
@synthesize addTime = _addTime;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.isDel = [self objectOrNilForKey:kBVBusinessModelDataIsDel fromDictionary:dict];
            self.distId = [self objectOrNilForKey:kBVBusinessModelDataDistId fromDictionary:dict];
            self.cityId = [self objectOrNilForKey:kBVBusinessModelDataCityId fromDictionary:dict];
            self.dataIdentifier = [self objectOrNilForKey:kBVBusinessModelDataId fromDictionary:dict];
            self.provinceId = [self objectOrNilForKey:kBVBusinessModelDataProvinceId fromDictionary:dict];
            self.title = [self objectOrNilForKey:kBVBusinessModelDataTitle fromDictionary:dict];
            self.intro = [self objectOrNilForKey:kBVBusinessModelDataIntro fromDictionary:dict];
            self.addTime = [self objectOrNilForKey:kBVBusinessModelDataAddTime fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.isDel forKey:kBVBusinessModelDataIsDel];
    [mutableDict setValue:self.distId forKey:kBVBusinessModelDataDistId];
    [mutableDict setValue:self.cityId forKey:kBVBusinessModelDataCityId];
    [mutableDict setValue:self.dataIdentifier forKey:kBVBusinessModelDataId];
    [mutableDict setValue:self.provinceId forKey:kBVBusinessModelDataProvinceId];
    [mutableDict setValue:self.title forKey:kBVBusinessModelDataTitle];
    [mutableDict setValue:self.intro forKey:kBVBusinessModelDataIntro];
    [mutableDict setValue:self.addTime forKey:kBVBusinessModelDataAddTime];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.isDel = [aDecoder decodeObjectForKey:kBVBusinessModelDataIsDel];
    self.distId = [aDecoder decodeObjectForKey:kBVBusinessModelDataDistId];
    self.cityId = [aDecoder decodeObjectForKey:kBVBusinessModelDataCityId];
    self.dataIdentifier = [aDecoder decodeObjectForKey:kBVBusinessModelDataId];
    self.provinceId = [aDecoder decodeObjectForKey:kBVBusinessModelDataProvinceId];
    self.title = [aDecoder decodeObjectForKey:kBVBusinessModelDataTitle];
    self.intro = [aDecoder decodeObjectForKey:kBVBusinessModelDataIntro];
    self.addTime = [aDecoder decodeObjectForKey:kBVBusinessModelDataAddTime];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_isDel forKey:kBVBusinessModelDataIsDel];
    [aCoder encodeObject:_distId forKey:kBVBusinessModelDataDistId];
    [aCoder encodeObject:_cityId forKey:kBVBusinessModelDataCityId];
    [aCoder encodeObject:_dataIdentifier forKey:kBVBusinessModelDataId];
    [aCoder encodeObject:_provinceId forKey:kBVBusinessModelDataProvinceId];
    [aCoder encodeObject:_title forKey:kBVBusinessModelDataTitle];
    [aCoder encodeObject:_intro forKey:kBVBusinessModelDataIntro];
    [aCoder encodeObject:_addTime forKey:kBVBusinessModelDataAddTime];
}

- (id)copyWithZone:(NSZone *)zone
{
    BVBusinessModelData *copy = [[BVBusinessModelData alloc] init];
    
    if (copy) {

        copy.isDel = [self.isDel copyWithZone:zone];
        copy.distId = [self.distId copyWithZone:zone];
        copy.cityId = [self.cityId copyWithZone:zone];
        copy.dataIdentifier = [self.dataIdentifier copyWithZone:zone];
        copy.provinceId = [self.provinceId copyWithZone:zone];
        copy.title = [self.title copyWithZone:zone];
        copy.intro = [self.intro copyWithZone:zone];
        copy.addTime = [self.addTime copyWithZone:zone];
    }
    
    return copy;
}


@end
